﻿@model CAF.WebSite.Mvc.Models.Users.LoginModel
@using CAF.WebSite.Application.WebUI.UI;
@using CAF.Infrastructure.Core;
@using CAF.WebSite.Application.WebUI;
@using CaptchaMvc.Models;
@{
    Layout = null;

    Html.AddTitleParts("会员登录");
    var registerUrl = Url.RouteUrl("Register");
    if (!String.IsNullOrEmpty(this.Context.Request.QueryString["returnUrl"]))
    {
        var webHelper = EngineContext.Current.Resolve<IWebHelper>();
        registerUrl = webHelper.ModifyQueryString(registerUrl, "returnurl=" + HttpUtility.UrlEncode(this.Context.Request.QueryString["returnUrl"]), null);
    }
    // add css assets
    var MediaRootPath = "~/Themes/AlphaDefault/";
    Html.AppendCssFileParts(
       MediaRootPath + "Content/css/global.css",
       MediaRootPath + "Content/css/login.css"
       );
    // add js assets (Head)
    Html.AppendScriptParts(ResourceLocation.Head,
        MediaRootPath + "Content/js/jquery.js",
        MediaRootPath + "Content/js/common.js"
       );
}
<!DOCTYPE html>

<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <title>@Html.WorkTitle(true)</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="@(Html.WorkMetaDescription())" />
    <meta name="keywords" content="@(Html.WorkMetaKeywords())" />
    <meta name="generator" content="Caf.NET @WorkVersion.CurrentFullVersion" />
    @Html.MetaAcceptLanguage()
    @Html.WorkCssFiles(this.Url, ResourceLocation.Head)
    @Html.WorkScripts(this.Url, ResourceLocation.Head)
    <link rel="shortcut icon" href="~/favicon.ico" />
</head>
<body>
    <div class="section">
        @Html.Action("SiteBar", "Common", new { area = "" })
        <div class="header_login">
            <div class="header_logo">
                <div class="login_logo"></div>
                <div class="logo_line"></div>
                <div class="logo_text">会员登录</div>
            </div>
            <div class="clear"></div>
        </div>
        <div class="center">
            <div class="center01">
                <div class="center_left">
                    <img src="~/Themes/AlphaDefault/Content/images/img_loginleft.jpg" width="717" height="441">
                </div>
                <div class="center_right">
                    <div class="center_login_top">
                        <i class="txt_login">登录</i><i class="engtxt_login"> LOGIN IN</i>
                        <a href="@Url.RouteUrl("register")">免费注册</a>
                    </div>
                    <div class="center_login">
                        <form id="defaultForm" method="post" class="form-horizontal" action="">
                            <div class="div_input">
                                <span>账户</span>
                                <input type="text" value="请输入账户/手机号" onblur="if(this.value==''){this.value='请输入账户/手机号'}"
                                       onfocus="if(this.value=='请输入账户/手机号'){this.value=''}" name="username" class="input_long input_username "
                                       id="txt_username">
                            </div>
                            <div class="div_input">
                                <span>密码</span>
                                <input type="password" value="" name="password" class=" input_long input_pwd " id="txt_pwd">
                            </div>
                            <div class="div_checked">
                                <span><input type="checkbox" id="rememberMe"  checked>&nbsp;记住密码</span>
                                <a href="@Url.Action("PasswordRecovery","Member")">忘记密码？</a>
                            </div>
                            <div class="div_code">
                                <input type="text" class="input_code input_true" id="txt_code" name="code" />
                                <span ><img id="checkCodeImg" title="点击更换验证码" src="@Url.Action("GetCheckCode","Member")" class="code" /></span>

                            </div>
                            <div class="div_submit">
                                <input type="button" class="input_submit" value="登  录" />
                            </div>
                        </form>
                    </div>
                    <div class="center_otherway">
                        @Html.Action("ExternalMethods", "ExternalAuthentication")
                        
        
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>

        @Html.Action("Footer", "Common", new { area = "" })
    </div>
    <script language="javascript" type="text/javascript">

        $(function () {

            //得到各个文本框的值
            var name;//用户名
            var pwd;  //密码
            var verify;//验证码

            //各个文本框的验证事件
            $("#txt_username").focus(function () {//用户名
                $("#txt_username").css("color", "#000").removeClass("input_false");
            }).blur(function () {
                name = $.trim($("#txt_username").val());
                if (name == "" || name == "请输入账户/手机号") {
                    $("#txt_username").addClass("input_false");
                    $("#txt_username").css("color", "#ef0000").val("请输入账户/手机号");
                    return false;
                }
                $("#txt_username").css("color", "#000").removeClass("input_false");
            });

            $("#txt_pwd").focus(function () {//密码
                $("#txt_pwd").attr("type", "password").css("color", "#000").val("");
            }).blur(function () {
                pwd = $("#txt_pwd").val().trim();
                if (pwd == "" || pwd == "请输入密码") {
                    $("#txt_pwd").addClass("input_false");
                    $("#txt_pwd").attr("type", "text").css("color", "#ef0000").val("请输入密码");
                    return false;
                }
                $("#txt_pwd").attr("type", "password").css("color", "#000").removeClass("input_false");
            });

            $("#txt_code").focus(function () {//验证码
                verify = $("#txt_code").val().trim();
                if (verify == "" || verify == "请输入验证码" || verify == "验证码输入错误") {
                    $("#txt_code").css("color", "#000").removeClass("input_false").val(" ");
                } else {
                    $("#txt_code").css("color", "#000").removeClass("input_false");
                }

            }).blur(function () {
                verify = $("#txt_code").val().trim();
                if (verify == "" || verify == "请输入验证码" || verify == "验证码输入错误") {
                    $("#txt_code").addClass("input_false");
                    $("#txt_code").css("color", "#ef0000").val("请输入验证码");
                    return false;
                }
                $("input[type='text']").css("color", "#000").removeClass("input_false");
            });
            $(document).keydown(function (event) {
                if (event.keyCode == 13) {
                    $(".input_submit").click();
                }
            });
            $(".input_submit").click(function () {

                //得到各个文本框的值
                name = $.trim($("#txt_username").val());
                pwd = $.trim($("#txt_pwd").val());
                verify = $.trim($("#txt_code").val());

                //得到系统验证码

                var styVer = $.trim($("#checkCode").val());

                if (name == "" || name == "请输入账户/手机号") {
                    $("#txt_username").addClass("input_false");
                    $("#txt_username").css("color", "#ef0000").val("请输入账户/手机号");
                    return false;
                }

                $("#txt_username").css("color", "#000").removeClass("input_false");
                if (pwd == "" || pwd == "请输入密码") {
                    $("#txt_pwd").addClass("input_false");
                    $("#txt_pwd").attr("type", "text").css("color", "#ef0000").val("请输入密码");
                    return false;
                }
                else if (pwd.length < 6 || pwd.length > 20) {
                    $("#txt_pwd").addClass("input_false");
                    $("#txt_pwd").attr("type", "text").css("color", "#ef0000").val("密码长度应在6-20位之间！");
                    return false;
                }
                if (verify == "" || verify == "请输入验证码" || verify == "验证码输入错误") {
                    $("#txt_code").addClass("input_false");
                    $("#txt_code").css("color", "#ef0000").val("请输入验证码");
                    return false;
                }

                //验证完成后执行的事件
                $.ajax({
                    type: 'POST',
                    async: false,
                    url: '/Member/Login',
                    data: {
                        username: $.trim($("#txt_username").val()),
                        password: $.trim($("#txt_pwd").val()),
                        checkCode: $.trim($("#txt_code").val()),
                        RememberMe:$("#rememberMe").val()
                    },
                    success: function (data) {
                        //alert(data);return;
                        if (data.Result) {
                                window.location.href = "/Member/AgentCenter";
                        } else {
                            if (data.Code == 99) {
                                alert("验证码错误，请重新填写!");
                            }
                            else if (data.Code == 100) {
                                alert("用户名或密码错误");
                            }
                            else if (data.Code == '199') {
                                alert("该用户被冻结,无法登录或使用");
                            }
                        }
                    }
                });
            });

            $('#checkCodeImg').click(function () {
                changeCheckCode();
            });
        });

        function changeCheckCode() {
            $('#checkCodeImg').attr('src', '/Member/GetCheckCode?time=' + new Date().getTime());
        }

    </script>
</body>
</html>